/*
 * TreeArray.cpp
 *
 *  Created on: 2013-2-4
 *      Author: tangwu
 */
#include "TreeArray.h"
#include <strings.h>
#include <stdio.h>
TreeArray::TreeArray(int _min_score, int _max_score, int _n, int _len)
	:Rank(_min_score, max_score, _n), len(_len){
	if(this->len <= 0){
		this->len = 2;
	}
	this->_score = new int[this->len];
	this->_sum = new int[this->len];
	/*
	 * 数据初始化为0
	 */
	bzero(this->_score, this->len*sizeof(int));
	bzero(this->_sum, this->len*sizeof(int));
}

bool TreeArray::update(int src_score, int des_score){
	return true;
}
int TreeArray::query(int score){
	return 0;
}
int TreeArray::lowb(int t){
	return t & (-t);
}
void TreeArray::add(int i, int v){
	this->_score[i] += v;
	for(; i < this->len; this->_sum[i] += v, i += lowb(i)) ;
}
int TreeArray::sum(int i){
	int s = 0;
	for(; i > 0; s += this->_sum[i], i -= lowb(i));
	return s;
}
TreeArray::~TreeArray(){
	delete[] this->_score;
	delete[] this->_sum;
}


